{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TensorFlow\n",
    "## Hello World"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "tf.logging.set_verbosity(tf.logging.ERROR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.13.1'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.version.VERSION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor(\"Const:0\", shape=(4, 3), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "m = tf.constant(np.arange(1, 12), shape=[4,3], dtype=tf.float32)\n",
    "print(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensor(\"random_uniform:0\", shape=(3, 4), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "n = tf.random_uniform([3,4], seed=888)\n",
    "print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.9368987  2.113493   2.048277   2.08671  ]\n",
      " [ 7.02995    6.137428   5.3143373  4.4081416]\n",
      " [11.123002  10.161362   8.580399   6.7295732]\n",
      " [14.568766  14.110989  11.497057   8.446618 ]]\n"
     ]
    }
   ],
   "source": [
    "result = tf.matmul(m, n)\n",
    "with tf.Session() as ss:\n",
    "    print(ss.run(result))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## TF Graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0.]\n",
      " [0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "# tf.get_default_graph\n",
    "new_graph = tf.Graph()\n",
    "with new_graph.as_default():\n",
    "    var = tf.get_variable('var', shape=[2,3], initializer=tf.zeros_initializer())\n",
    "    assert var.graph is new_graph\n",
    "with tf.Session(graph=new_graph) as ss:\n",
    "    tf.global_variables_initializer().run()\n",
    "    with tf.variable_scope(\"\", reuse=tf.AUTO_REUSE):\n",
    "        print(ss.run(tf.get_variable('var')))\n",
    "# device of graph\n",
    "# with new_graph.device('/device:GPU:0'):"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
